package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.SysCommunity;
import com.ruoyi.community.service.ISysCommunityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小区表Controller
 * 
 * @author ruoyi
 * @date 2022-10-14
 */
@RestController
@RequestMapping("/community/community")
public class SysCommunityController extends BaseController
{
    @Autowired
    private ISysCommunityService sysCommunityService;

    /**
     * 查询小区表列表
     */
    @PreAuthorize("@ss.hasPermi('community:community:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCommunity sysCommunity)
    {
        startPage();
        List<SysCommunity> list = sysCommunityService.selectSysCommunityList(sysCommunity);
        return getDataTable(list);
    }

    /**
     * 导出小区表列表
     */
    @PreAuthorize("@ss.hasPermi('community:community:export')")
    @Log(title = "小区表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCommunity sysCommunity)
    {
        List<SysCommunity> list = sysCommunityService.selectSysCommunityList(sysCommunity);
        ExcelUtil<SysCommunity> util = new ExcelUtil<SysCommunity>(SysCommunity.class);
        util.exportExcel(response, list, "小区表数据");
    }

    /**
     * 获取小区表详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:community:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(sysCommunityService.selectSysCommunityById(id));
    }

    /**
     * 新增小区表
     */
    @PreAuthorize("@ss.hasPermi('community:community:add')")
    @Log(title = "小区表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCommunity sysCommunity)
    {
        return toAjax(sysCommunityService.insertSysCommunity(sysCommunity));
    }

    /**
     * 修改小区表
     */
    @PreAuthorize("@ss.hasPermi('community:community:edit')")
    @Log(title = "小区表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCommunity sysCommunity)
    {
        return toAjax(sysCommunityService.updateSysCommunity(sysCommunity));
    }

    /**
     * 删除小区表
     */
    @PreAuthorize("@ss.hasPermi('community:community:remove')")
    @Log(title = "小区表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysCommunityService.deleteSysCommunityByIds(ids));
    }
}
